www.gusucode.com > VC++ 客户管理系统(SQL Serve)-源码程序 > VC++ 客户管理系统(SQL Serve)-源码程序/code/Program/addoper.cpp

    // addoper.cpp : implementation file
//

#include "stdafx.h"
#include "khmanager.h"
#include "addoper.h"
#include "ado.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// addoper dialog


addoper::addoper(CWnd* pParent /*=NULL*/)
	: CDialog(addoper::IDD, pParent)
{
	//{{AFX_DATA_INIT(addoper)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void addoper::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(addoper)
	DDX_Control(pDX, IDC_EDIT4, m_edit4);
	DDX_Control(pDX, IDC_EDIT3, m_edit3);
	DDX_Control(pDX, IDC_EDIT2, m_edit2);
	DDX_Control(pDX, IDC_EDIT1, m_edit1);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(addoper, CDialog)
	//{{AFX_MSG_MAP(addoper)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// addoper message handlers

BOOL addoper::OnInitDialog() 
{
	CDialog::OnInitDialog();
	this->m_edit1.EnableWindow(false);
	this->autonum();
	
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
void addoper::autonum()
{
	
		ado rst3;
		
	rst3.rstOpen("select * from tb_user");
	rst3.MoveLast();
	CString mm=rst3.GetFieldValue("user_id");
	int xuhao=atoi(mm.Right(3));
	xuhao+=1;
	mm.Format("ID%03d",xuhao);
	this->m_edit1.EnableWindow(false);
	
	this->m_edit1.SetWindowText(mm);
	rst3.close();
}

void addoper::OnButton1() 
{
CString edit1,edit2,edit3,edit4,TSQL;
this->m_edit1.GetWindowText(edit1);
this->m_edit2.GetWindowText(edit2);
this->m_edit3.GetWindowText(edit3);
this->m_edit4.GetWindowText(edit4);
if(edit2.IsEmpty())
{MessageBox("请输入用户名","提示");
return;}
if(edit3.Compare(edit4)!=0)
{MessageBox("两次密码输入不同","提示");
this->m_edit3.SetWindowText("");
this->m_edit4.SetWindowText("");
return;}
ado rst;
//TSQL.Format("INSERT INTO tb_user values('%s','%s','%s')",edit1,edit2,edit3);
TSQL.Format("INSERT INTO tb_user values('%s','%s','%s')",edit1,edit2,edit3);
rst.ExecuteSQL(TSQL);
MessageBox("添加成功","提示");
this->autonum();
this->m_edit2.SetWindowText("");
this->m_edit3.SetWindowText("");
this->m_edit4.SetWindowText("");
	
}

void addoper::OnButton2() 
{
this->EndDialog(true);	
}

BOOL addoper::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(pMsg->message==WM_KEYDOWN && pMsg->wParam==13)
		pMsg->wParam=9;	
	return CDialog::PreTranslateMessage(pMsg);
}